package cn.lijian.goods.cart.domain;

import java.math.BigDecimal;
import java.util.ArrayList;

import cn.lijian.goods.book.domain.Book;
import cn.lijian.goods.user.domain.User;

public class CartItem {

	private String cartItemId;
	private int quantity;//数量
	private Book book;//条目对应的图书
	private User user;//所属用户
	private double subtotal;
	public void setSubtotal(double subtotal) {
		this.subtotal = subtotal;
	}

	//计算小计
	public double getSubtotal(){
		//使用 BigDecimal 不会有误差
		BigDecimal b1=new BigDecimal(book.getCurrPrice()+"");
		BigDecimal b2=new BigDecimal(quantity+"");
		BigDecimal b3=b1.multiply(b2);//   b3 = b1*b2
		
		return book.getCurrPrice()*quantity;
	}

	public String getCartItemId() {
		return cartItemId;
	}
	public void setCartItemId(String cartItemId) {
		this.cartItemId = cartItemId;
	}
	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	public Book getBook() {
		return book;
	}
	public void setBook(Book book) {
		this.book = book;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	@Override
	public String toString() {
		return "CartItem [cartItemId=" + cartItemId + ", quantity=" + quantity
				+ ", book=" + book + ", user=" + user + "]";
	}
	public CartItem() {
		super();
		// TODO Auto-generated constructor stub
	}
	public CartItem(String cartItemId, int quantity, Book book, User user) {
		super();
		this.cartItemId = cartItemId;
		this.quantity = quantity;
		this.book = book;
		this.user = user;
	}
	
	
	
}
